<?php 
if(!defined('INEZCMS')){
	exit('Access Denied');
}
if(empty($userlogininfo)){
    
    jump(SITEURL."/login.html", '您还没有登录!');
}
    $ezuser=$ezhand->select("member","*","id=".$userlogininfo["uid"]);

    $pagesize=5;
	no_cache();    
	$do=$_GET['do']?$_GET['do']:'list';
	$page = !($_GET['page'])?'1':intval($_GET['page']);
	$page2=($page-1)*$pagesize;
	
	if($do=='list'){
		$total = $ezhand->count('zhibo_subject',"	operate_user='".$ezuser["username"]."'");
		$zhibo_row=$ezhand->select_all('zhibo_subject',"*","	operate_user='".$ezuser["username"]."' order by subjectid desc limit $page2,$pagesize");
        
        
        
        
	}
	elseif($do=='send'){
	   
       
       
   	   
	   $subjectid=intval($_GET["subjectid"]);
       if(empty($subjectid)){
            jump('-1','图文直播主题未找到！');
       }
       $zhibo_option=$ezhand->select_all('zhibo_option',"*"," subjectid=".$subjectid." ");
       $zhiboinfo=$ezhand->select('zhibo_subject',"*","subjectid=".$subjectid." and 	operate_user='".$ezuser["username"]."' ");
       if(empty($zhiboinfo)){
         jump('-1','图文直播主题未找到！');
       }
       $zhibo_row_list=$ezhand->select_all('zhibo_list',"*"," subjectid=".$subjectid." ");
       $zhibopicdata=$ezhand->select_all('zhibo_images',"*"," subjectid=".$subjectid." ");
	}
	elseif($do=='del'){
		$ids=$_GET['ids'];
		foreach($ids as $id){
			if($id>0){
				$sql="delete from ".$BIAOTOU."message where id='".$id."'";
				$ezhand->query($sql);
			}
		}
		jump('-1','删除成功');
	}
	elseif($do=='save'){
	   
		$content=htmlspecialchars($_POST['content']);
        $speaker=trim($_POST["speaker"]);
        $authcode=trim($_POST["authcode"]);
        $sendtime=trim($_POST["sendtime"]);
        $subjectid=trim(intval($_POST["subjectid"]));
        $isred=intval($_POST["isred"]);
        $data["status"]=0;
        if(empty($authcode)){
           $data["msg"]="发布失败!"; 
           echo json_encode($data);
           exit;              
        }
        if(empty($content)){
           $data["msg"]="没有填写发布内容!"; 
           echo json_encode($data);
           exit;              
        }
                
        if(empty($subjectid)){
           $data["msg"]="没有选择图文直播主题!"; 
           echo json_encode($data);
           exit;              
        }        
        $md5string=md5($subjectid.$sendtime.EZKEY);
        if($md5string<>$authcode){
           $data["msg"]="发布验证失败，请咨询管理员!"; 
           echo json_encode($data);
           exit;              
        }
        $urow=$ezhand->select('zhibo_option',"*","options='".$speaker."' and subjectid=".$subjectid);
        if(empty($urow)){
            $odata=array("subjectid"=>$subjectid,"options"=>$speaker);
            $ezhand->insert('zhibo_option',$odata);
            
        }
        $username=$ezuser["username"];
        $ip=get_client_ip();
        $sendtime=time();
        $field_arr=array();
        $field_arr["username"]=$username;
        $field_arr["ip"]=$ip;
        $field_arr["sendtime"]=$sendtime;
        $field_arr["speaker"]=$speaker;
        $field_arr["subjectid"]=$subjectid;
        $field_arr["speakinfo"]=$content;
        $field_arr["isred"]=$isred;
        
        
        $ezhand->insert('zhibo_list', $field_arr);
        
        if($isred>0){
            $sp="<font color=red>【".$speaker.":】</font>";
        }else{
            $sp=$speaker;
        }
        $data["status"]=1;
        $data["msg"]='
                    <table border="0" cellpadding="0" cellspacing="1" width="740">
            <tr>
            <td colspan="2" align="left" class="zhibozhuchi">'.$sp.'</td>
            </tr>
            <tr>
            <td width="100">&nbsp;</td>
            <td class="zhibocontent">'.nl2br($content).'</td>
            </tr>
            <tr>
            <td align="right" colspan="2" class="zhibotime">'.date("Y-m-d H:i:s",$sendtime).'</td>
            </tr></table>
        '; 
        echo json_encode($data);
        exit;           
        
	}
	elseif($do=='savepic'){

		$subject=htmlspecialchars($_POST['subject'],ENT_QUOTES);
        $authcode=trim($_POST["authcode1"]);
        $sendtime=trim($_POST["sendtime1"]);
        $subjectid=trim(intval($_POST["subjectid1"]));
        
        if(empty($subjectid)){
           $msg="没有选择图文直播主题!"; 
           jump_error($msg);
           exit;              
        } 
        $md5string=md5($subjectid.$sendtime.EZKEY);
        if($md5string<>$authcode){
           $data["msg"]="验证失败，请咨询管理员!"; 
           jump_error($data["msg"]);
           exit;              
        }
        header("Content-Type: text/html; charset=utf-8");
        include_once EZROOT."/libs/Uploader.class.php";
         $config = array(
            "savePath" => ($path == "1" ? "upload/" : "upload1/"),
            "maxSize" => 2000, //单位KB
            "allowFiles" => array(".gif", ".png", ".jpg", ".jpeg", ".bmp")
        );                           
        $up = new Uploader("picname", $config);
        $info = $up->getFileInfo();
        $field_arr=array();
        $field_arr["username"]=$ezuser["username"];
        $field_arr["ip"]=get_client_ip();
        $field_arr["sendtime"]=time();
        $field_arr["subject"]=$subject;
        $field_arr["subjectid"]=$subjectid;
        $field_arr["images"]=$info["url"];
        $field_arr["originalName"]=$info["originalName"];
        $ezhand->insert('zhibo_images', $field_arr);
        
        $total = $ezhand->count('zhibo_images'," subjectid='".$subjectid."'");
        
        $html='<a class="pl2" href="'.SITEURL.'/'.$info["url"].'" target="_blank"><img src="'.thumb($info["url"],211,146).'" alt="'.$subject.'" width="211" height="146" />'.$subject.'</a>';
        
        echo script("parent.resetupload(".$total.",'".$html."');");
        exit();
       
       
	}
	unset($ezhand);

?>